package org.nokatag.tagjava;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.jsp.JspException;

public class AccordionButton extends BodyNokaTag{
	private static final long serialVersionUID = -3150480514983503585L;
	private String name=null;
	private String aligning="bottom"; //bottom 底端，left 左边,right 右边
	private String onclick=null;//单击时调用的方法
	private String img = null;
	private List<Map<String,String>> button=new ArrayList<Map<String,String>>();//
	public int doEndTag() throws JspException {
		 StringBuilder stringBuilder = new StringBuilder();
         stringBuilder.append("<li>");
         String imgHtml = "";
         if(img!=null)
        	 imgHtml="<img src=\""+img+"\" style=\"vertical-align:middle;\"/>";
         if(onclick!=null){
        	 stringBuilder.append("<a style=\"display:inline-block;\"onclick=\""+onclick+"\"><h3>"+imgHtml+name+"</h3></a>");
         } else{
        	 stringBuilder.append("<h3>"+imgHtml+name+"</h3>");
         }
         stringBuilder.append("<div class=\"acc-section\">");
         stringBuilder.append("<div class=\"acc-content\">");
         for(Map<String,String> map:button){
        	 stringBuilder.append("<button  class=\"noka_tag_button\"  onclick=\"window.open('"+map.get("url")+"','"+map.get("target")+"');\">");
        	 if(aligning.equalsIgnoreCase("bottom")){
	        	 stringBuilder.append("<br><img src=\""+map.get("image")+"\"/></br>");
	        	 stringBuilder.append(map.get("name"));
        	 }else if(aligning.equalsIgnoreCase("left")){
        		 stringBuilder.append(map.get("name"));
	        	 stringBuilder.append("<img src=\""+map.get("image")+"\"/>");
        	 }else if(aligning.equalsIgnoreCase("right")){
	        	 stringBuilder.append("<img src=\""+map.get("image")+"\"/>");
	        	 stringBuilder.append(map.get("name"));
        	 }
        	 stringBuilder.append("</button><br>");
         }
         stringBuilder.append("</div>");
         stringBuilder.append("</div>");
         stringBuilder.append("</li>");
		try {
			pageContext.getOut().write(stringBuilder.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		 return SKIP_BODY;
	}
	public String getAligning() {
		return aligning;
	}
	public void setAligning(String aligning) {
		this.aligning = aligning;
	}
	public List<Map<String, String>> getButton() {
		return button;
	}
	public void setButton(List<Map<String, String>> button) {
		this.button = button;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getOnclick() {
		return onclick;
	}
	public void setOnclick(String onclick) {
		this.onclick = onclick;
	}
	public String getImg() {
		return img;
	}
	public void setImg(String img) {
		this.img = img;
	}
}
